import request from '@/utils/request'
import apiConfig from '@/api/config'
import qs from 'qs'

// 获取字典分页
export const getDictList = params => {
  return request({
    url: `${apiConfig.baseApi}/dicts`,
    method: 'get',
    params
  })
}

export const upload_file = data => {
  return request({
    url: `${apiConfig.baseApi}/files`,
    method: 'post',
    data
  })
}

// 添加父级字典
export const addPidDict = data => {
  return request({
    url: `${apiConfig.baseApi}/dicts/pid`,
    method: 'post',
    data
  })
}

// 添加子级字典
export const addPidChildrenDict = data => {
  return request({
    url: `${apiConfig.baseApi}/dicts/children`,
    method: 'post',
    data
  })
}
// 根据父编码获取字典列表
export const getPidChildrenDict = params => {
  return request({
    url: `${apiConfig.baseApi}/dicts/${params.id}/children`,
    method: 'get'
    // data
  })
}
// 根据id获取字典信息
export const getDictInfo = id => {
  return request({
    url: `${apiConfig.baseApi}/dicts/${id}`,
    method: 'get'
    // params
  })
}
// 批量修改字典
export const editDicts = data => {
  return request({
    url: `${apiConfig.baseApi}/dicts`,
    method: 'put',
    data
  })
}
// 删除字典
export const deleteDictById = id => {
  return request({
    url: `${apiConfig.baseApi}/dicts/${id}`,
    method: 'delete'
    // data
  })
}

// 获取菜单
export const getMenusList = data => {
  return request({
    url: `${apiConfig.baseApi}/resources/tree`,
    method: 'get',
    params: data
  })
}

// 更改菜单状态
export const changeResourceStatusApi = data => {
  return request({
    url: `${apiConfig.baseApi}/resources/modify-status`,
    method: 'post',
    data
  })
}

// 删除菜单
export const delResource = data => {
  return request({
    url: `${apiConfig.baseApi}/resources/${data}`,
    method: 'delete'
  })
}

// 获取当前菜单详情
export const getMenusResource = data => {
  return request({
    url: `${apiConfig.baseApi}/resources/${data}`,
    method: 'get'
  })
}

// 修改菜单
export const updateResource = data => {
  return request({
    url: `${apiConfig.baseApi}/resources`,
    method: 'put',
    data
  })
}

// 批量添加菜单
export const insertResource = data => {
  return request({
    url: `${apiConfig.baseApi}/resources`,
    method: 'post',
    data
  })
}

// 新增角色
export const addRoles = data => {
  return request({
    url: `${apiConfig.baseApi}/roles`,
    method: 'post',
    data
  })
}
// 修改角色
export const editRoles = data => {
  return request({
    url: `${apiConfig.baseApi}/roles`,
    method: 'put',
    data
  })
}

// 删除角色
export const deleteRoles = id => {
  return request({
    url: `${apiConfig.baseApi}/roles/${id}`,
    method: 'delete'
  })
}

// 获取角色信息
export const getRolesInfo = data => {
  return request({
    url: `${apiConfig.baseApi}/roles/${id}`,
    method: 'get'
  })
}

// 获取角色列表
export const getRolesList = params => {
  return request({
    url: `${apiConfig.baseApi}/roles`,
    method: 'get',
    params
  })
}
// 角色绑定资源
export const updateRolesBind = data => {
  return request({
    url: `${apiConfig.baseApi}/roles/bind`,
    method: 'post',
    data
  })
}
// 获取角色绑定的资源
export const getRolesBind = id => {
  return request({
    url: `${apiConfig.baseApi}/roles/${id}/resources`,
    method: 'get'
  })
}
// 启用、禁用角色
export const enableRoles = (id, data) => {
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    url: `${apiConfig.baseApi}/roles/enable/${id}`,
    method: 'post',
    data: qs.stringify(data)
  })
}

// 新增机构
export const addOrganization = data => {
  return request({
    url: `${apiConfig.baseApi}/org`,
    method: 'post',
    data
  })
}
// 编辑机构
export const updateOrganization = data => {
  return request({
    url: `${apiConfig.baseApi}/org`,
    method: 'put',
    data
  })
}
// 政府机构详情
export const getOrganizationInfo = id => {
  return request({
    url: `${apiConfig.baseApi}/org/${id}`,
    method: 'get'
  })
}
// 生成内部机构
export const addChildrenOrganization = id => {
  return request({
    url: `${apiConfig.baseApi}/org/create-children/${id}`,
    method: 'get'
  })
}
// 修改状态（停用，启用）
export const updateOrganizationStatus = data => {
  return request({
    url: `${apiConfig.baseApi}/org/update-ststus`,
    method: 'get',
    params: data
  })
}
// 子集列表
export const getChildrenOrganizationList = data => {
  return request({
    url: `${apiConfig.baseApi}/org/next-children/${data.pId}`,
    method: 'get'
  })
}

// 账号管理 是否禁用
export const changeResourceStatus = (id, data) => {
  return request({
    url: `${apiConfig.baseApi}/users/enable/${id}`,
    method: 'post',
    params: data
  })
}

// 账号管理 解锁
export const cancelDisable = id => {
  return request({
    url: `${apiConfig.baseApi}/users/unlock/${id}`,
    method: 'post'
  })
}

// 账号管理-角色分配
export const saveRoleInfos = data => {
  return request({
    url: `${apiConfig.baseApi}/users/grant`,
    method: 'post',
    data
  })
}

// 账号管理 重置密码
export const resetPWD = id => {
  return request({
    url: `${apiConfig.baseApi}/users/reset-password/${id}`,
    method: 'post'
  })
}

// 账号管理 删除用户
export const delAccount = id => {
  return request({
    url: `${apiConfig.baseApi}/users/${id}`,
    method: 'delete'
  })
}

// 账号管理 修改/添加用户
export const accountAddSubmit = (data, requestType) => {
  return request({
    url: `${apiConfig.baseApi}/users`,
    method: requestType,
    data
  })
}

// 账号管理 获取账号列表
export const getAccountList = data => {
  return request({
    url: `${apiConfig.baseApi}/users`,
    method: 'get',
    params: data
  })
}

// 账号管理 获取当前绑定角色
export const getRoleInfos = id => {
  return request({
    url: `${apiConfig.baseApi}/users/${id}/roles`,
    method: 'get'
  })
}

// 账号管理 获取所有角色
export const getAllRoleInfos = data => {
  return request({
    url: `${apiConfig.baseApi}/roles/all`,
    method: 'get',
    params: data
  })
}

// 账号管理 获取当前用户
export const getAccountEditInfos = id => {
  return request({
    url: `${apiConfig.baseApi}/users/${id}`,
    method: 'get'
  })
}

// 账号管理 获取所有机构树
export const getOrgOptions = data => {
  return request({
    url: `${apiConfig.baseApi}/org/tree`,
    method: 'get'
  })
}
// 基础参数 新增参数配置
export const addSysparam = data => {
  return request({
    url: `${apiConfig.baseApi}/sysparam`,
    method: 'post',
    data
  })
}
// 基础参数 修改参数配置
export const editSysparam = data => {
  return request({
    url: `${apiConfig.baseApi}/sysparam`,
    method: 'put',
    data
  })
}
// 基础参数 参数配置分页
export const getSysparamList = data => {
  return request({
    url: `${apiConfig.baseApi}/sysparam`,
    method: 'get',
    params: data
  })
}
// 基础参数 根据id获取参数配置
export const getSysparamInfo = id => {
  return request({
    url: `${apiConfig.baseApi}/sysparam/${id}`,
    method: 'get'
  })
}
// 基础参数 获取参数配置通过code
export const getSysparamCode = code => {
  return request({
    url: `${apiConfig.baseApi}/sysparam/${code}`,
    method: 'get'
  })
}
// 修改密码
export const updatepwdSubmit = data => {
  return request({
    url: `${apiConfig.baseApi}/auths/change-password`,
    method: 'post',
    data
  })
}
// 基础参数获取文件
export const getSysparamFileServer = () => {
  return request({
    url: `${apiConfig.baseApi}/auths/sys-param`,
    method: 'get'
  })
}
// 养老机构登记评定模板设置
export const yljgStarRatingTemplateTree = () => {
  return request({
    url: `${apiConfig.businessApi}/star-rating-template/tree`,
    method: 'get'
  })
}
export const yljgStarRatingDetail = id => {
  return request({
    url: `${apiConfig.businessApi}/star-rating-template/${id}`,
    method: 'get'
  })
}
export const yljgStarRatingEdit = data => {
  return request({
    url: `${apiConfig.businessApi}/star-rating-template`,
    method: 'put',
    data
  })
}
export const yljgStarRatingAdd = data => {
  return request({
    url: `${apiConfig.businessApi}/star-rating-template`,
    method: 'post',
    data
  })
}
export const yljgStarRatingDel = id => {
  return request({
    url: `${apiConfig.businessApi}/star-rating-template/${id}`,
    method: 'delete'
  })
}

// 更新区划缓存
export const areasCache = params => {
  return request({
    url: `${apiConfig.baseApi}/areas/cache`,
    method: 'get',
    params: params
  })
}

// 更新字典缓存
export const dictsRefresh = params => {
  return request({
    url: `${apiConfig.baseApi}/dicts/refresh`,
    method: 'get',
    params: params
  })
}

// 登录日志查询
export const getLoginLogs = params => {
  return request({
    url: `${apiConfig.baseApi}/login_logs`,
    method: 'get',
    params: params
  })
}


// 日志查询
export const getSystemLogs = params => {
  return request({
    url: `${apiConfig.businessApi}/operate-logs`,
    method: 'get',
    params: params
  })
}